#include "SemanticNodeBlockLeave.h"

/**
 *  @fn	SemanticNodeBlockLeave::SemanticNodeBlockLeave(const SyntaxTreeNode *leaveNodeParent,
 *  	SemanticNode *parent)
 * 
 *  @brief	Constructor. 
 * 
 *  @author	Nikola Novak
 *  @date	6/25/2009
 * 
 *  @param	advanceNodeParent	If non-null, the advance node parent.
 *  @param	parent				If non-null, the parent.
 */
SemanticNodeBlockLeave::SemanticNodeBlockLeave(const SyntaxTreeNode *leaveNodeParent, SemanticNode *parent) : SemanticNode(parent), LabeledNode(leaveNodeParent->Nodes->GetData(0)) {
	unitsFrom = (leaveNodeParent->Nodes->GetData(1)->Nodes->GetData(0)->Nodes->GetData(1)->Nodes->GetCount() > 0);
}
/**
 *  @fn	bool SemanticNodeBlockLeave::hasUnitsFrom(void)
 * 
 *  @brief	Query if this object has units from. 
 * 
 *  @author	Nikola Novak
 *  @date	6/25/2009
 * 
 *  @return	true if units from, false if not.
 */
bool SemanticNodeBlockLeave::hasUnitsFrom(void) {
	return unitsFrom;
}
/**
 *  @fn	void SemanticNodeBlockLeave::setUnitsFrom(SemanticNodeExpression *unitsNo)
 * 
 *  @brief	Sets the units from. 
 * 
 *  @author	Nikola Novak
 *  @date	6/25/2009
 * 
 *  @param	unitsNo	If non-null, the units no.
 */
void SemanticNodeBlockLeave::setUnitsFrom(SemanticNodeExpression *unitsNo) {
	unitsFromExpression = unitsNo;
}
/**
 *  @fn	void SemanticNodeBlockLeave::setStorage(SemanticNodeExpression *storage)
 * 
 *  @brief	Sets a storage. 
 * 
 *  @author	Nikola Novak
 *  @date	6/25/2009
 * 
 *  @param	storage	If non-null, the storage.
 */
void SemanticNodeBlockLeave::setStorage(SemanticNodeExpression *storage) {
	storageExpression = storage;
}
/**
 *  @fn	std::string SemanticNodeBlockLeave::toDebugString(int tab)
 * 
 *  @brief	Converts a tab to a debug string. 
 * 
 *  @author	Nikola Novak
 *  @date	6/25/2009
 * 
 *  @param	tab	The tab.
 * 
 *  @return	This object as a std::string.
 */
std::string SemanticNodeBlockLeave::toDebugString(int tab) {
	std::ostringstream res;
 for (int i = 0; i < tab; i++)	res << DEBUG_STRING_RAZMAK;
	res << getLabelsDebugString() << ": leave ";
	if (!unitsFrom) res << "1 ";
	else {
		res << std::endl << ((SemanticNode *)unitsFromExpression)->toDebugString(tab + 1);
		for (int i = 0; i < tab; i++)	res << DEBUG_STRING_RAZMAK;
	}
	res << "units from" << std::endl << ((SemanticNode *)storageExpression)->toDebugString(tab + 1);
	return res.str();
}
